﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Configuration;
using Microsoft.Extensions.Logging.Console;
using NetC100K;
using NetC100K.Setting;
using System;
using System.Threading.Tasks;

namespace NetC100KHost
{
    public class Program
    {
        public async static Task Main(string[] args)
        {
            var host = new HostBuilder()
                .ConfigureAppConfiguration((configHost) =>
                {
                    configHost.AddJsonFile("appsettings.json");
                })
                .ConfigureLogging((hostContext, configLogging) =>
                {
                    configLogging.AddLog4Net();
                    configLogging.SetMinimumLevel(LogLevel.Information);
                    //configLogging.AddConsole((config) =>
                    //{
                    //    config.IncludeScopes = true;
                    //    config.Format = ConsoleLoggerFormat.Systemd;
                    //    config.TimestampFormat = "yyyy-MM-dd HH:mm:ss:fff";
                    //});
                })
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddSingleton<ServerPool>();
                    services.AddHostedService<HostService>();
                    services.AddHostedService<TimedHostedService>();
                })
                .UseConsoleLifetime()
                .Build();
            await host.StartAsync();
        }
    }
}
